package com.sh.tcp;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.SocketChannel;

/**
* @comments
* @author  zg
* @date 2018年4月6日
*/
public class ClientChannelMap {
	
	private static Map<String, ChannelHandlerContext> map = new ConcurrentHashMap<>();

    public static void add(String clientId, ChannelHandlerContext channel) {
        map.put(clientId, channel);
    }

    public static ChannelHandlerContext get(String clientId) {
        return map.get(clientId);
    }

    public static void remove(ChannelHandlerContext channel) {
        for (Map.Entry<String, ChannelHandlerContext> entry : map.entrySet()) {
            if (entry.getValue() == channel) {
                map.remove(entry.getKey());
            }
        }
    }
    
    /*private static Map<String, Channel> map = new ConcurrentHashMap<>();
    
    public static void add(String clientId, Channel channel) {
    	map.put(clientId, channel);
    }
    
    public static Channel get(String clientId) {
    	return map.get(clientId);
    }
    
    public static void remove(Channel channel) {
    	for (Map.Entry<String, Channel> entry : map.entrySet()) {
    		if (entry.getValue() == channel) {
    			map.remove(entry.getKey());
    		}
    	}
    }*/
    
}
